<?php

	/*
	 * AJAX call to call an edit form for editing of an SMS from the database.
	 * SMSs are stored in the table "inbox".
	 *
	 * Variables:
	 *   id (int) : record ID in the database
	 *              if not given: new SMS.
	 *
	 * Returns: HTML code (string)
	 *
	 */


	$clean["id"] = round($_GET["id"]);
	if($clean["id"] > 0){
		/* An SMS id is provided: load the message */
		$sql = mysql_query("SELECT * FROM inbox WHERE ID=".$clean["id"]." LIMIT 1");
		if(mysql_num_rows($sql) > 0){
			$row = mysql_fetch_array($sql, MYSQL_ASSOC);
			echo '
				Edit SMS:<br />
			';
		}
	}
	if(!isset($row)){
		/* No SMS ID was given, or the SMS we tried to load did not exist anymore */
		$row = array("TextDecoded"=>"");
		echo '
		Add new SMS:<br />
		';
	}

	/* SMS editing form is the same for new and old SMSs */
	/* form field "id" contains SMS ID, is 0 for new SMSs */
	echo '
		<textarea id="editbox_textarea" style="width:397px; height: 70px;">'.utf8_encode($row["TextDecoded"]).'</textarea><br />
		<a href="javascript:editsmsclose()" style="display: block; float:left"><img src="'.$url_prefix.'images/cross.png" style="border:0px;" /></a>
		<a href="javascript:editsmssave()" style="display: block; float:right"><img src="'.$url_prefix.'images/disk.png" style="border:0px;" /></a>
		<input type="hidden" id="id" name="id" value="'.$clean["id"].'" />
	';
?>
